package com.open4cn.simulator.device.xrite;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.open4cn.simulator.core.device.DeviceStatus;
import com.open4cn.simulator.core.device.DeviceStatusDO;
import com.open4cn.simulator.core.device.IDeviceStatusRecover;
import com.open4cn.simulator.core.ext.XriteStatus;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-19 21:44
 */
public class XriteStatusRecover implements IDeviceStatusRecover {

    @Override
    public DeviceStatus recover(DeviceStatusDO deviceStatusDO) {
        if (null == deviceStatusDO) {
            return null;
        }

        JSON parse = JSONUtil.parse(deviceStatusDO.getStatusJson());
        String deviceId = parse.getByPath("$.deviceId", String.class);
        String brand = parse.getByPath("$.brand", String.class);
        String model = parse.getByPath("$.model", String.class);

        // 解析XriteStatus
        JSON data = parse.getByPath("$.data", JSON.class);
        String currentUV = data.getByPath("$.currentUV", String.class);
        String currentSpecularGloss = data.getByPath("$.currentSpecularGloss", String.class);
        String currentAperture = data.getByPath("$.currentAperture", String.class);
        XriteStatus xriteStatus = new XriteStatus(currentUV, currentSpecularGloss, currentAperture);

        return new DeviceStatus(deviceId, brand, model, xriteStatus);
    }
}
